<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>调度派车 - TMS</title>
    <link rel="stylesheet" href="/view/frame/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/view/frame/static/css/global.css?v=1.0">
    <link rel="stylesheet" href="/view/tms/static/css/iframe.css?v=1.0">
    <style>
        .layui-form-item {
            margin: 0;
        }
        
        .layui-form-item .layui-inline {
            margin-bottom: 0;
            margin-right: 6px;
        }
        
        .layui-form-item .layui-inline .layui-input-inline {
            margin-right: 4px;
            width: 160px;
        }
        
        .layui-form-item .layui-inline .layui-form-mid {
            margin-right: 4px;
        }
        
        .fold {
            font-size: 23px;
            font-style: normal;
            font-weight: bold;
            cursor: pointer;
        }
        
        .sub-table .layui-table-view {
            margin: 3px;
            margin-left: -1px;
        }
        
        .sub-tool-bar {
            margin: 0 30px 5px 0;
            text-align: left;
            line-height: 30px;
        }
        
        .sub-tool-bar a {
            margin: 0 10px;
            color: #055bae;
            text-decoration: underline;
        }
        
        .time-btn-sel {
            background: #cecece;
            color: #000;
        }
        
        searchMore {
            display: none;
        }
    </style>
</head>

<body>
    <!--start: 搜索-->
    <div class="panel-handle search-bar">
        <form class="layui-form layui-form-pane" autocomplete="off">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label" style="width:90px;">做柜时间</label>
                    <div class="layui-input-inline">
                        <input type="text" name="doarkDateStart" id="doarkDateStart" readonly placeholder="起始时间" class="layui-input">
                    </div>
                    <div class="layui-form-mid">-</div>
                    <div class="layui-input-inline">
                        <input type="text" name="doarkDateEnd" id="doarkDateEnd" readonly placeholder="截止时间" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-inline" style="width:auto;">
                        <div class="layui-btn-group">
                            <button class="layui-btn layui-btn-primary" data-btn="doTime" data-id="today">今天</button>
                            <button class="layui-btn layui-btn-primary" data-btn="doTime" data-id="tomorrow">明天</button>
                            <button class="layui-btn layui-btn-primary" data-btn="doTime" data-id="yesterday">昨天</button>
                        </div>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label" style="width:90px;">客户名称</label>
                    <div class="layui-input-inline">
                        <input type="text" name="customerName" placeholder="客户名称" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layui-btn-danger" lay-submit lay-filter="search"><i class="layui-icon">&#xe615;</i>查询</button>
                    <button class="layui-btn layui-btn-primary" type="reset" style="margin:0;">重置</button>
                </div>
            </div>
            <div class="layui-form-item" style="margin-top:10px;">
                <div class="layui-inline">
                    <label class="layui-form-label" style="width:90px;">S/O No.</label>
                    <div class="layui-input-inline">
                        <input type="text" name="soNumber" placeholder="S/O号码" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label" style="width:90px;">订单号码</label>
                    <div class="layui-input-inline">
                        <input type="text" name="orderNo" placeholder="订单号码" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label" style="width:90px;">拖车车牌</label>
                    <div class="layui-input-inline">
                        <input type="text" name="carNo" placeholder="拖车车牌" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label" style="width:90px;">司机</label>
                    <div class="layui-input-inline">
                        <input type="text" name="driverName" placeholder="司机姓名" class="layui-input">
                    </div>
                </div>
            </div>
        </form>
        <div class="clr"></div>
    </div>
    <!--end: 搜索-->

    <!--start: 按钮组-->
    <div class="panel-handle btns-bar">
        <div class="layui-btn-group fl">
            <button class="layui-btn" data-type="allData">全部</button>
            <button class="layui-btn layui-btn-normal" data-type="dispatchCar">派车</button>
            <button class="layui-btn layui-btn-normal" data-type="dispatchDispose">改派处理</button>
            <button class="layui-btn layui-btn-normal" data-type="dispatchChange">中途换车</button>
            <button class="layui-btn layui-btn-normal" data-type="marginArk">孖柜</button>
            <button class="layui-btn layui-btn-normal" data-type="printWaybill">打印运单</button>
            <button class="layui-btn layui-btn-normal" data-type="repealArk">确认撤柜</button>
            <button class="layui-btn layui-btn-normal" data-type="updateBrokenNo">录报关单号</button>
        </div>
        <div class="clr"></div>
    </div>
    <!--end: 按钮组-->

    <!--start:表格列表-->
    <table class="layui-hide" id="tableList" lay-filter="tbar"></table>
    <!--end:表格列表-->

    <!--start:快捷搜索-->
    <div id="shortBar" style="display:none;">
        <dl>
            <dt>统计信息</dt>
            <dd><a href="">未派车<span class="layui-badge">50</span></a></dd>
            <dd><a href="">已派车<span class="layui-badge">43</span></a></dd>
            <dd><a href="">今天<span class="layui-badge">18</span></a></dd>
            <dd><a href="">明天<span class="layui-badge">18</span></a></dd>
        </dl>
    </div>
    <!--end:快捷搜索-->

    <script type="text/html" id="statusTpl">
        {{setStatus(d.status)}}
    </script>
    <script type="text/html" id="addressTpl">
        {{# if(d.address != null){ }} {{# var $newArr = d.address.split(';') }} {{# if($newArr.length > 0){ }} {{# $newArr = deWeightArr($newArr) }} {{$newArr.join(' || ')}} {{# } }} {{# } }}
    </script>
    <script type="text/html" id="singleTypeTpl">
        {{setSingleType(d.singleBilltype)}}
    </script>
    <script type="text/html" id="doarkDateTpl">
        {{ new Date(d.doarkDate).format('MM-dd hh:mm') }}
    </script>
    <script type="text/html" id="arkTypeTpl">
        {{# if(d.arkType != null){ }} {{# if(d.arkType.indexOf('RF') > -1){ }}
        <span style="color:#34a8ff;">{{d.arkType}}</span> {{# }else{ }} {{d.arkType}} {{# } }} {{# } }}
    </script>
    <script type="text/html" id="putarkPositionTpl">
        {{setPutarkPosition(d.putarkPosition)}}
    </script>
    <script type="text/html" id="hasCashTpl">
        {{# if(d.hasCash == 1){ }}
        <input type="checkbox" name="hasCash" lay-skin="primary" value="true" checked disabled> {{# }else{ }}
        <input type="checkbox" name="hasCash" lay-skin="primary" value="false" disabled> {{# } }}
    </script>
</body>
<script charset="utf-8" src="/view/frame/static/js/jquery.min.js?v=1.0"></script>
<script charset="utf-8" src="/view/frame/layui/layui.js"></script>
<script charset="utf-8" src="/view/frame/static/js/lang_zh_CN.js?v=1.0"></script>
<script charset="utf-8" src="/view/tms/static/js/tms_index.js?v=1219"></script>

<script charset="utf-8" src="/view/frame/static/js/errorCodeMap.js"></script>
<script charset="utf-8" src="/view/frame/static/js/HC.js?v=1.4"></script>
<script charset="utf-8" src="/view/tms/static/js/validator.js"></script>
<script charset="utf-8" src="/view/tms/static/js/bizUtil.js"></script>

<script>
    layui.use(['form', 'layer', 'table', 'tms_tab', 'laydate'], function() {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
            laydate = layui.laydate,
            tmsTab = layui.tms_tab,
            $ = layui.jquery;

        //初始化日期时间
        laydate.render({
            elem: '#doarkDateStart'
        });
        laydate.render({
            elem: '#doarkDateEnd'
        });

        //今天，昨天，明天
        $('button[data-btn="doTime"]').on('click', function() {
            $('button[data-btn="doTime"]').removeClass('time-btn-sel');
            $(this).addClass('time-btn-sel');
            var $dataId = $(this).attr('data-id');
            var $d = {};
            if ($dataId == 'today') {
                $date = new Date().format('yyyy-MM-dd');
                $d.todayTime = $date;
            } else if ($dataId == 'tomorrow') {
                $date = new Date(new Date().getTime() + 24 * 60 * 60 * 1000).format('yyyy-MM-dd');
                $d.tomorrowTime = $date;
            } else if ($dataId == 'yesterday') {
                $date = new Date(new Date().getTime() - 24 * 60 * 60 * 1000).format('yyyy-MM-dd');
                $d.yesterdayTime = $date;
            }
            setTableData($d);
            return false;
        });

        //初始化表格数据
        setTableData({});

        //监听提交
        form.on('submit(search)', function(data) {
            var v1 = data.field.doarkDateStart,
                v2 = data.field.doarkDateEnd;
            if (v1.length > 0 && v2.length == 0) {
                layer.msg('请选择截止时间');
                return false;
            }
            if (v1.length == 0 && v2.length > 0) {
                layer.msg('请选择起始时间');
                return false;
            }
            if (v1.length > 0 && v2.length > 0) {
                v1 = new Date(v1);
                v2 = new Date(v2);
                if (v1 > v2) {
                    layer.msg('截止时间要大于起始时间');
                    return false;
                }
            }

            var $saveData = data.field;
            console.log(JSON.stringify($saveData));
            setTableData($saveData);
            return false;
        });

        //方法级渲染
        function setTableData($searchData) {
            var $pageSize = 15;

            table.render({
                elem: '#tableList',
                url: '/ucenter/tms/waybill/waybill/selectSendCar.shtml',
                method: 'post',
                where: $searchData,
                response: {
                    statusCode: 'SUCCESS',
                    dataName: 'objects'
                },
                cols: [
                    [{
                        checkbox: true,
                        fixed: true
                    }, {
                        field: 'id',
                        title: '序号',
                        width: 80,
                        sort: true,
                        align: 'center'
                    }, {
                        field: 'status',
                        title: '状态',
                        width: 100,
                        sort: true,
                        align: 'center',
                        templet: '#statusTpl'
                    }, {
                        field: 'customerName',
                        title: '客户名称',
                        width: 100,
                        sort: true,
                        align: 'center'
                    }, {
                        field: 'doarkDate',
                        title: '做柜时间',
                        width: 100,
                        sort: true,
                        align: 'center',
                        templet: '#doarkDateTpl'
                    }, {
                        field: 'address',
                        title: '装卸地点',
                        width: 100,
                        align: 'center',
                        templet: '#addressTpl'
                    }, {
                        field: 'soNumber',
                        title: 'S/O',
                        width: 125,
                        align: 'center'
                    }, {
                        field: 'arkType',
                        title: '箱型',
                        width: 60,
                        align: 'center',
                        templet: '#arkTypeTpl'
                    }, {
                        field: 'putarkPosition',
                        title: '位置',
                        width: 60,
                        align: 'center',
                        templet: '#putarkPositionTpl'
                    }, {
                        field: 'heavyAddress',
                        title: '提柜地点',
                        width: 100,
                        align: 'center'
                    }, {
                        field: 'freightPrice',
                        title: '运费上限',
                        width: 100,
                        sort: true,
                        align: 'center'
                    }, {
                        field: 'freightGain',
                        title: '运费涨幅',
                        width: 100,
                        sort: true,
                        align: 'center'
                    }, {
                        field: 'carNo',
                        title: '车牌',
                        width: 110,
                        sort: true,
                        align: 'center'
                    }, {
                        field: 'driverName',
                        title: '司机',
                        width: 80,
                        sort: true,
                        align: 'center'
                    }, {
                        field: 'driverMobile',
                        title: '司机手机',
                        width: 110,
                        align: 'center'
                    }, {
                        field: 'freight',
                        title: '运费',
                        width: 100,
                        align: 'center'
                    }, {
                        field: 'prepayFare',
                        title: '预付车费',
                        width: 90,
                        align: 'center'
                    }, {
                        field: 'hasCash',
                        title: '现金结算',
                        width: 80,
                        align: 'center',
                        templet: '#hasCashTpl'
                    }, {
                        field: 'arkNo',
                        title: '箱号',
                        width: 115,
                        align: 'center'
                    }, {
                        field: 'sealNo',
                        title: '铅封号',
                        width: 110,
                        align: 'center'
                    }, {
                        field: 'brokenNo',
                        title: '报关单号（可编辑）',
                        width: 160,
                        align: 'center',
                        edit: 'text'
                    }, {
                        field: 'orderNo',
                        title: '订单号码',
                        width: 140,
                        align: 'center'
                    }, {
                        field: 'jobNo',
                        title: '作业号',
                        width: 150,
                        align: 'center'
                    }, {
                        field: 'singleBilltype',
                        title: '急单类型',
                        width: 80,
                        align: 'center',
                        templet: '#singleTypeTpl'
                    }]
                ],
                id: 'dataReload',
                page: false,
                height: 'full-178',
                size: 'sm',
                even: true
            });

            //添加快捷搜索
            var $shortBarHtml = $('#shortBar').html();
            $('.layui-table-tool').prepend('<div class="short-bar">' + $shortBarHtml + '</div>');
        }

        var active = {
            //全部
            allData: function() {
                window.location.reload();
                //setTableData({});
            },
            //派车
            dispatchCar: function() {
                var checkStatus = table.checkStatus('dataReload'),
                    data = checkStatus.data;
                if (data.length == 0) {
                    parent.layer.alert('你还未选中数据！');
                } else if (data.length > 1) {
                    parent.layer.alert('只能选择一条数据！');
                } else {
                    if (data[0].status != 330) {
                        parent.layer.alert('只有状态为等待派车的运单才可以派车！');
                        return false;
                    }
                    parent.layer.open({
                        type: 2,
                        title: '派车（' + data[0].id + '）',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['700px', '500px'],
                        content: 'dispatchCar.html?id=' + data[0].id
                    });
                }
            },
            //改派处理
            dispatchDispose: function() {
                var checkStatus = table.checkStatus('dataReload'),
                    data = checkStatus.data;
                if (data.length == 0) {
                    parent.layer.alert('你还未选中数据！');
                } else if (data.length > 1) {
                    parent.layer.alert('只能选择一条数据！');
                } else {
                    if (data[0].status != 404) {
                        parent.layer.alert('只有状态为改派审核中的运单才可以改派处理！');
                        return false;
                    }
                    var $driverObjs = getDriverByWbid(data[0].id),
                        $driverName = $driverObjs.frontDriverName,
                        $driverMobile = $driverObjs.frontDriverMobile,
                        $driverIdCard = $driverObjs.frontDriverIdCard,
                        $driverCar = $driverObjs.frontDriverCar,
                        $driverInputTxt = !$driverObjs.driverInput ? '<span>（未录入）</span>' : '',
                        $carInputTxt = !$driverObjs.carInput ? '<span>（未录入）</span>' : '',
                        $html = '<style>' +
                        '.driverMsg {margin:10px 20px; line-height:26px;}' +
                        '.driverMsg li span {color:#34a8ff;}' +
                        '</style>' +
                        '<div class="driverMsg"><ul>' +
                        '<li>司机姓名：' + $driverName + $driverInputTxt + '</li>' +
                        '<li>身份证号：' + $driverIdCard + '</li>' +
                        '<li>手机号码：' + $driverMobile + '</li>' +
                        '<li>驾驶车辆：' + $driverCar + $carInputTxt + '</li>' +
                        '</ul></div>';
                    parent.layer.open({
                        type: 1,
                        title: '改派推荐司机信息（' + data[0].id + '）',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['350px', '250px'],
                        content: $html,
                        btn: ['同意', '拒绝'],
                        btn1: function(index) {
                            parent.layer.closeAll();
                            updateSendHand(data[0].id, 'agree');
                        },
                        btn2: function(index) {
                            updateSendHand(data[0].id, 'disagree');
                        }
                    });
                }

                //接口处理
                function updateSendHand(id, type) {
                    var $saveData = {
                        id: id,
                        handType: type
                    }
                    $.ajax({
                        type: 'POST',
                        url: '/ucenter/tms/waybill/waybill/updateSendHand.shtml',
                        dataType: "json",
                        contentType: "application/json",
                        data: $saveData,
                        success: function(d) {
                            var $code = d.code,
                                $msg = d.msg,
                                $objects = d.objects;

                            if ($code === 'SUCCESS') {
                                window.location.reload();
                            } else {
                                parent.layer.msg('操作失败！');
                            }
                        }
                    });
                    return false;
                }
            },
            //中途换车
            dispatchChange: function() {
                var checkStatus = table.checkStatus('dataReload'),
                    data = checkStatus.data;
                if (data.length == 0) {
                    parent.layer.alert('你还未选中数据！');
                } else if (data.length > 1) {
                    parent.layer.alert('只能选择一条数据！');
                } else {
                    if (data[0].status < 401 || data[0].status >= 500) {
                        parent.layer.alert('只有状态为司机接单至作业完成的运单才可以中途换车！');
                        return false;
                    }
                    parent.layer.open({
                        type: 2,
                        title: '中途换车（' + data[0].id + '）',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['700px', '460px'],
                        content: 'dispatchChange.html?id=' + data[0].id
                    });
                }
            },
            //孖柜
            marginArk: function() {
                var checkStatus = table.checkStatus('dataReload'),
                    data = checkStatus.data;
                if (data.length == 0) {
                    parent.layer.alert('你还未选中数据！');
                } else if (data.length > 1) {
                    parent.layer.alert('只能选择一条数据！');
                } else {
                    if (data[0].arkType.indexOf('20') == -1 || data[0].status != 330) {
                        parent.layer.alert('只有箱型尺寸为20且状态为等待派车的运单才可以孖柜！');
                        return false;
                    }
                    parent.layer.open({
                        type: 2,
                        title: '孖柜（' + data[0].id + '）',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['80%', '80%'],
                        content: 'marginArk.html?id=' + data[0].id
                    });
                }
            },
            //打印运单
            printWaybill: function() {
                var checkStatus = table.checkStatus('dataReload'),
                    data = checkStatus.data;
                if (data.length == 0) {
                    parent.layer.alert('你还未选中数据！');
                } else if (data.length > 1) {
                    parent.layer.alert('只能选择一条数据！');
                } else {
                    parent.layer.open({
                        type: 2,
                        title: '打印运单（' + data[0].id + '）',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['90%', '95%'],
                        content: 'printWbill.html?id=' + data[0].id
                    });
                }
            },
            //确认撤柜
            repealArk: function() {
                var checkStatus = table.checkStatus('dataReload'),
                    data = checkStatus.data;
                if (data.length == 0) {
                    parent.layer.alert('你还未选中数据！');
                } else if (data.length > 1) {
                    parent.layer.alert('只能选择一条数据！');
                } else {
                    if (data[0].status != 310) {
                        parent.layer.msg('只有申请撤销的运单才能确认撤柜！');
                        return false;
                    }

                    parent.layer.open({
                        type: 2,
                        title: '确认撤柜（' + data[0].id + '）',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['80%', '80%'],
                        content: 'repealArk.html?id=' + data[0].id
                    });
                }
            },
            //录报关单号
            updateBrokenNo: function() {
                var checkStatus = table.checkStatus('dataReload'),
                    data = checkStatus.data;
                if (data.length == 0) {
                    parent.layer.alert('你还未选中数据！');
                } else {
                    layer.prompt({
                        title: '录入报关单号'
                    }, function(text, index) {
                        layer.close(index);
                        if (text.length > 50) {
                            layer.msg('报关单号长度过长');
                            return false;
                        } else if (!$jsReg.userName.test(text)) {
                            layer.msg('报关单号只能由英文和数字组成');
                            return false;
                        } else {
                            //接口
                            var $ids = [];
                            for (var $i = 0; $i < data.length; $i++) {
                                $ids.push(data[$i].id);
                            }
                            var $saveData = {
                                ids: $ids,
                                brokenNo: text
                            }
                            addBrokenNo($saveData);
                        }
                    });
                }
            }
        };

        $('.btns-bar .layui-btn').on('click', function() {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        //监听单元格编辑
        table.on('edit(tbar)', function(obj) {
            var value = obj.value,
                data = obj.data,
                field = obj.field;
            var $saveData = {
                ids: [data.id],
                brokenNo: value
            }
            addBrokenNo($saveData);
        });

        //录入报关单号接口
        function addBrokenNo(objs) {
            $.ajax({
                type: 'POST',
                url: '/ucenter/tms/waybill/waybill/updateBrokenNo.shtml',
                dataType: "json",
                contentType: "application/json",
                data: JSON.stringify(objs),
                success: function(d) {
                    var $code = d.code,
                        $msg = d.msg,
                        $objects = d.objects;

                    if ($code === 'SUCCESS') {
                        window.location.reload();
                    } else {
                        parent.layer.msg('操作失败！');
                    }
                }
            });
            return false;
        }
    });
</script>

</html>